﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace WebLog.Db.Update
{
    internal class update_v2 : baseUpdateDatabase
    {
        public update_v2()
        {
            this.V = 2;
            this.Memo = "升级weblog表";
        }
        internal override async Task UpdateAction()
        {
            await sqliteHelper.ExecuteNonQueryAsync(@"
                    DROP TABLE if exists weblogTmp;
                    create table if not exists weblogTmp(
                        id integer PRIMARY KEY autoincrement,                -- 设置主键
                        Path VARCHAR(500),Success BOOLEAN,ContentType VARCHAR(100),Headers TEXT,IsHttps BOOLEAN,Method VARCHAR(20),
                        Date DATETIME,Body TEXT,Query TEXT,Data TEXT,Message TEXT
                    );
                    INSERT INTO weblogTmp(path,Success,ContentType,Headers,IsHttps,Method,Date,Body,Query,Data,Message)
                        select path,Success,ContentType,Headers,IsHttps,Method,Date,Body,Query,Data,Message
                        from weblog;
                    drop table weblog;
                    alter table weblogTmp rename to weblog;");
            /*
             //创建临时表结构
            //复制数据过去
            //改临时表为weblog表
            //使数据都有id
            //空间回收
             */
        }
    }
}
